package com.thuanngo.maps;


import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.GoogleMap.OnMyLocationChangeListener;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;

import android.location.Location;
import android.os.Bundle;
import android.app.Activity;
import android.app.Dialog;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
import android.widget.TextView;

public class MainActivity extends FragmentActivity implements OnMyLocationChangeListener {

	GoogleMap googleMap;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		/*int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
		if(status!=ConnectionResult.SUCCESS){
			int requestCode=10;
			Dialog dialog =  GooglePlayServicesUtil.getErrorDialog(status, this, requestCode);
			dialog.show();
		 }else{
			 SupportMapFragment fmMap= (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
			 googleMap= fmMap.getMap();
			 googleMap.setMyLocationEnabled(true);
			 googleMap.setOnMyLocationChangeListener(this);
		 }*/
		 SupportMapFragment fmMap= (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
		 googleMap= fmMap.getMap();
		 googleMap.setMyLocationEnabled(true);
		 googleMap.setOnMyLocationChangeListener(this);
   }

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	@Override
	public void onMyLocationChange(Location arg0) {
		// TODO Auto-generated method stub
		TextView tv= (TextView) findViewById(R.id.textView1);
		double latitude = arg0.getLatitude();
		double longitude = arg0.getLongitude();
		LatLng latLg= new LatLng(latitude, longitude);
		googleMap.moveCamera(CameraUpdateFactory.newLatLng(latLg));
		googleMap.animateCamera(CameraUpdateFactory.zoomTo(15));
	}

}
